<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/getParameter.js"></script>
    <script src="js/jquery-1.11.0.min.js"></script>
    <script src="js/jquery-3.3.1.js"></script>
</head>
<body>
<div id="content"></div>
<a href="javascript:history.go(-1)">返回</a>
<script>
    $(function (){
        let tid=getParameter("tid");
        $.post("statistics/updateLook",{tid},function (resp){
            if(resp.succ){
                console.log("查看");
            }
        })

        let route_lis="";
        $.post("route/findOne",{tid},function (resp){
            var data = resp.data;
            //判断alreadyUp
            var color="";
            if(data.alreadyUp){
                color="pink";
            }else {
                color="black"
            }
            var li = `<div>
                         <div><span>${data.name}</span><span>${data.type}</span></div>
                         <div><h1>${data.title}</h1><p>${data.content}</p></div>
                         <div>
                             <div>
                             <div><span class="iconfont icon-ai-eye"></span><span>${data.countLook}</span></div>
                             <div><span style="color: ${color}" onclick='up(${data.tid})' id="up${data.tid}" class="iconfont icon-dianzan"></span><span id="upNum${data.tid}">${data.countUp}</span></div></div>
                            <span>${data.release_time}</span>
                         </div>
                     </div>`;
            route_lis += li;
            $("#content").html(route_lis);
        }
        
        )
    })

    function up(tid){
        $.post("statistics/update",{tid:tid},function (resp){
            if(resp.succ){
                if(resp.data==true){
                    $(`#up${tid}`).css("color","pink");
                    console.log(document.getElementById(`upNum${tid}`).innerHTML);
                    var num= parseInt(document.getElementById(`upNum${tid}`).innerHTML)+1;
                    $(`#upNum${tid}`).html(num);
                }else {
                    $(`#up${tid}`).css("color","black");
                    var num= parseInt(document.getElementById(`upNum${tid}`).innerHTML)-1;
                    $(`#upNum${tid}`).html(num);
                }


            }else {
                location.href="login.html";
            }
        })
    }
</script>
</body>
</html>